<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2022/2/25
 * Time: 11:28
 */

namespace app\admin\controller;


use think\Db;
use think\Request;

class Fyb extends Base
{
    /**
     * 分佣管理
     * @return mixed|\think\response\Json
     */
    public function index(){
        if(request()->isAjax ()){
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 50;
            $count = Db::name('bo_fy_config')->where('bfc_status', 1)->count();// 获取总条数
            $lists = Db::name('bo_fy_config')
                ->where('bfc_status', 1)
                ->field('bfc_id, bfc_name, bfc_content, bfc_up_name')
                ->page($Nowpage,$limits)
                ->order('bfc_sort asc')
                ->select();
            
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        return $this->fetch();
    }
    
    /**
     * 编辑
     * @return mixed|\think\response\Json
     */
    public function fyEdit(){
        $bfc_id = input('bfc_id');
        if(Request::instance()->isPost()){
            $bfc_content = trim(input('bfc_content'), ' ');
            $res = Db::table('up_bo_fy_config')->where('bfc_id', $bfc_id)
                ->update(['bfc_content' => $bfc_content, 'bfc_updatetime' => date('Y-m-d H:i:s')]);
            if($res){
                return json(['code' => 200, 'msg' => '编辑成功']);
            }else{
                return json(['code' => 100, 'msg' => '编辑失败']);
            }
        }
        $config = Db::table('up_bo_fy_config')->where('bfc_id', $bfc_id)->field('bfc_name, bfc_content')->find();
        return $this->fetch('', ['config' => $config, 'bfc_id' => $bfc_id]);
    }
}